package com.nus.servlets;

import com.nus.beans.ProjectRemark;
import com.nus.database.LoginDBManager;
import com.nus.database.ProjectsDBManager;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.Connection;

/**
 * Created by IntelliJ IDEA.
 * User: dell
 * Date: 11/2/12
 * Time: 12:59 AM
 * To change this template use File | Settings | File Templates.
 */
public class ViewAddProjectRemarkServlet extends AbstractServlet{
    public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
        doGet(request, response);
    }

    public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
        String projectRemarksId = request.getParameter("projectRemark");
        String targetPage = null;
        if(projectRemarksId != null){
            targetPage =  "/WEB-INF/update_project_remark.jsp";
            int projectRemarksIdInt = Integer.parseInt(projectRemarksId);
            Connection connection = getUserDatabaseConnection(request);
            ProjectsDBManager projectDBManager = new ProjectsDBManager(connection);
            ProjectRemark projectRemark = projectDBManager.getProjectRemark(projectRemarksIdInt);
            request.setAttribute("projectRemark", projectRemark);
        } else {
            targetPage = "/WEB-INF/add_project_remark.jsp";
        }
        RequestDispatcher requestDispatcher = request.getRequestDispatcher(targetPage);
        requestDispatcher.forward(request, response);
    }
}
